package com.sdry.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.entity.PartComponent;
import com.sdry.entity.PartComponentExample;
import com.sdry.service.PartComponentService;
import com.sdry.utils.TableResult;

/**
 * 
* @Title: PartComponentController.java
* @Package com.sdry.web.controller
* @Description: 库存表
* @author cb
* @date 2018年7月31日
* @version V1.0
 */
@Controller
@RequestMapping("/stock")
public class PartComponentController {
	
	@Resource
	private PartComponentService partComponentService;

	/**
	 * 跳转到库存表
	 * @return
	 */
	@RequestMapping("/pageStock")
	public String pageStock() {
		
		
		return "stock/list";
	}
	
	/**
	 * 分页
	 * @param limit 大小
	 * @param offset 当前
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public TableResult list(String departmentname ,String statu,@RequestParam(value="limit",required=false)String limit,@RequestParam(value="offset",required=false)String offset) {
		
		PageHelper.startPage(Integer.parseInt(offset), Integer.parseInt(limit));
    	
		
		Map<String, Object> map = new HashMap<>();
		
		map.put("code", departmentname);
		map.put("name", statu);
		
		
		List<PartComponent> list = partComponentService.selectlist(map);
    	
    	PageInfo<PartComponent> info = new PageInfo<PartComponent>(list);
    	
    	TableResult tableResult = new TableResult(info.getTotal(), info.getList()); 
    	
		return tableResult;
		
	}
	
	/**
	 * 查找所有
	 * @return
	 */
	@RequestMapping("/selectAll")
	@ResponseBody
	public TableResult selectAll() {
		
		PartComponentExample example = new PartComponentExample();
		
		List<PartComponent> list = partComponentService.selectByExample(example);
		
		TableResult tableResult = new TableResult(null, list); 
		
		return tableResult;
	}
	
}
